import { Renderer } from 'marked';
// import { IUserInfo } from "./parseMd.insterface"
import { hasDuplicateKeys } from "./tools"

/**
 * 返回第一个出现paragraph 的对象
 * @param self
 */
const getFirstParagraphObj = (self: Renderer) => {
    const arr: any = self.options?.tokenizer?.lexer?.tokens;
    //判断第一个出现段落对象 paragraph
    const res = arr.find((item: any) => {
        return item.type === 'paragraph';
    });
    return parseUserBaseInfo(res)
};

const parseUserBaseInfo = (userInfo: any) => {
    const { raw } = userInfo
    const userInfoArr: [] = raw.split("\n");
    const userInfoObj = {}
    userInfoArr.forEach((item: any) => {
        const info: [] = item.split(": ")
        userInfoObj[info[0]] = info[1];
    })
    // console.log(userInfoObj, 'userInfoObj')
    //如果存在相同的key 则提示
    // if (!hasDuplicateKeys(userInfoObj)) {
    //     return false
    // }
    return userInfoObj
}


export { getFirstParagraphObj, parseUserBaseInfo };
